<template>
  <div class="message-box">
    <div>
        <div class="mes-title">
          <span>{{messageObj.contentType}} </span><span class="mes-num">{{messageObj.num}}</span>
        </div>
        <div class="mes-content">
          <div class="mes-left">
            <img :src="messageObj.iconUrl" alt="">
          </div>
          <div class="mes-right">
            <div class="mes-text">
              <!-- <span class="mes-type">【】</span> -->
              {{messageObj.content}}
            </div>
            <div class="mes-other">
              <span>{{messageObj.name}}</span>
              <span>{{messageObj.time}}</span>
            </div>
          </div>
        </div>
        <div class="bottom-poreate">
          <el-button size="mini" @click="openAllPage">查看详情</el-button>
          <el-button type="primary" size="mini" @click="readAll(true, '')">全部已读</el-button>
        </div>
    </div>
  </div>
</template>

<script>
 import { getMessageAllApi,getReadMessageApi } from "../api/myHome"
export default {
  name: '',
  mixins: [],
  components: {
  },
  props: {
    messageObj: {
      num: Number,
      content: String,
      contentType: String,
      name: String,
      time: String,
      iconUrl: String,
      itemObj: Object
    },
  },
  data () {
    return {
      sid: this._sid,
      testUrl:window.portalUrl+'/df?groupValue=icon&fileValue=64&sid=ba0a126c-25f9-425f-9d2d-2928c59baee6&repositoryName=%21appresource&appId=com.actionsoft.apps.workbench&attachment=true&fileName=icon64.png&lastModified=0&v=1.110&time=1605859220000',
      allMessageUrl: null
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {
    this.getMessageAllFn()
  },
  methods: {
    getMessageAllFn() {
      getMessageAllApi(this.sid).then(res => {
        if(res.result == 'ok') {
          this.allMessageUrl = res.data.url
        }
      })
    },
    openAllPage() {
      // this.$notify.closeAll()
      this.closeParternMessageFn()
      window.open(this.allMessageUrl)
    },
    readAll(bool, id) { // true全部已读
      // let com.actionsoft.apps.notification_read_all_message
      let nid = bool ? '^^^all' :  ''
      let registerId = bool ? '' : ''
     
      getReadMessageApi(this.sid, nid, registerId).then(res => {
        if(res.result == 'ok') {
          // alert("接口")
          // this.$notify.closeAll()
          this.closeParternMessageFn()
          this.$message({
              message: '全部已读',
              type: 'success'
            })
        }
      })
    },
    closeParternMessageFn() {
      this.$store.commit('resetMessageStore')
      this.$emit("closeParternMessageFn", false)
    }
  }
}
</script>

<style scoped lang="scss"></style>
